package com.geoboard.fragments;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.geoboard.ActivityInterface;
import com.geoboard.R;
import com.geoboard.entity.Board;
import com.geoboard.service.ListAdapterBoard;

public class BoardTextFrag extends ListFragment{
	
	/**** Members **************************************************/
	String TAG = this.getClass().getSimpleName();
	ArrayList<Board> mBoards;
	
	/**** Android Callback Methods *********************************/
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		Log.d(TAG, "onCreateView()");
        mBoards = ((ActivityInterface)getActivity()).getMapFrag().getVisibleBoards();
        if(mBoards != null) {
        	Log.d(TAG, String.format("listing %d boards", mBoards.size()));
        	this.setListAdapter(new ListAdapterBoard(mBoards, getActivity()));
        }
		return inflater.inflate(R.layout.frag_board_text, container, false);		
	}
	
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Notify the parent activity of selected item
        ((ActivityInterface)getActivity()).showPosts(mBoards.get(position));
        
    }
}
